package BC120_小乐乐与二段数;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (sc.hasNext()){
            if (sc.nextInt() == 0){
                break;
            }
            int n = sc.nextInt();
            for (int i = 1; ; i++){
                long m = n * i;
                if (isBinaryNumber(m)){
                    System.out.printf("%d: %ld", n, m);
                }
            }
        }
    }

    private static boolean isBinaryNumber(long m) {
        ArrayList<Long> list = new ArrayList<>();
        while (m > 0){
            list.add(m % 10);
            m /= 10;
        }
        int n = list.size();
        long firstNum = list.get(0);
        long lastNUm = list.get(n);

        int changIndex = list.indexOf(lastNUm);

        List<Long> list1 = list.subList(0, changIndex);
        List<Long> list2 = list.subList(changIndex, n);
        list1.sort(Long::compareTo);
        list2.sort(Long::compareTo);

        HashSet<Long> set1 = new HashSet<Long>(list1);
        HashSet<Long> set2 = new HashSet<>(list2);

        if (set1.size() == 1 && set2.size() == 1){
            return true;
        }else {return false;}
    }
}
